package com.example.demo.utils;

import com.example.demo.entity.Task;
import com.example.demo.entity.User;
import com.example.demo.result.R;
import com.example.demo.result.Renum;

import java.util.List;

//工具类
public class RUtils {
    //调用成功，且返回数据体
    public static R success(Object object){
        R r = new R();
        r.setCode(Renum.SUCCESS.getCode());
        r.setMessage(Renum.SUCCESS.getMessage());
        r.setData(object);
        return r;
    }

    //调用成功，且返回列表
    public static R success(List<Object> objects){
        R r = new R();
        r.setCode(Renum.ADD.getCode());
        r.setMessage(Renum.ADD.getMessage());
        r.setData(objects);
        return r;
    }

    //调用成功，且返回用户列表
    public static R success(Integer number){
        R r = new R();
        r.setCode(Renum.ADD.getCode());
        r.setMessage(Renum.ADD.getMessage());
        r.setData(number);
        return r;
    }

    //成功只返回信息
    public static R success(Renum renum){
        R r = new R();
        r.setCode(renum.getCode());
        r.setMessage(renum.getMessage());
        return r;
    }

    //返回失败信息
    public static R error(Renum renum)
    {
        R r = new R();
        r.setCode(renum.getCode());
        r.setMessage(renum.getMessage());
        return r;
    }

    public static R error(Integer code, String message)
    {
        R r= new R();
        r.setCode(code);
        r.setMessage(message);
        return r;
    }


}
